package cn.openea.perpartner.cms.web.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.openea.perpartner.cms.web.entity.CmsOperLog;
import cn.openea.perpartner.cms.web.mapper.CmsOperLogMapper;
import cn.openea.perpartner.cms.web.service.ICmsOperLogService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 操作日志记录(CmsOperLog)表服务实现类
 *
 * @author makejava
 * @since 2022-08-12 14:42:07
 */
@Service("cmsOperLogService")
public class CmsOperLogServiceImpl extends ServiceImpl<CmsOperLogMapper, CmsOperLog> implements ICmsOperLogService {
    private static final String OPERATOR_TYPE_OF_RECYCLE = "回收";
    private static final String OPERATOR_TYPE_OF_ASSIGN = "指派";

    @Override
    public List<CmsOperLog> selectList(String userId, String searchStr) {
        LambdaQueryWrapper<CmsOperLog> wrapper = new LambdaQueryWrapper<>();
        if (StrUtil.isNotBlank(userId)) {
            wrapper.eq(CmsOperLog::getCreateUser, userId);
        }

        if (StrUtil.isNotBlank(searchStr)) {
            wrapper.and(wrap -> {wrap.like(CmsOperLog::getCreateTime, searchStr)
                        .or().like(CmsOperLog::getOperContent, searchStr)
                        .or().like(CmsOperLog::getTitle, searchStr);
                if (OPERATOR_TYPE_OF_RECYCLE.contains(searchStr)) {
                    wrapper.eq(CmsOperLog::getOperatorType, "0");
                }
                if (OPERATOR_TYPE_OF_ASSIGN.contains(searchStr)) {
                    wrapper.eq(CmsOperLog::getOperatorType, "1");
                }
            });

        }
        wrapper.eq(CmsOperLog::getStatus, "0");
        wrapper.orderByDesc(CmsOperLog::getCreateTime);
        return list(wrapper);
    }
}

